package cn.fy.consumer.controller;

import cn.fy.consumer.client.UserClient;
import cn.fy.consumer.pojo.User;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
@RestController
@RequestMapping("consumer/user")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

//    @Autowired
//    private DiscoveryClient discoveryClient;

    @Autowired
    private UserClient userClient;

    @GetMapping("{id}")
    public String findUserById(@PathVariable("id") Long id){
        //通过服务的id获取服务实例的集合
//        List<ServiceInstance> instancesById = discoveryClient.getInstances("service-provider");
//        ServiceInstance instance = instancesById.get(0);

        return userClient.findUserById(id).toString();

//                this.restTemplate.getForObject("http://service-provider/user/"+id, User.class);
    }
}
